package com.qfedu.stussm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.stussm.dao.SrewardDao;
import com.qfedu.stussm.entity.Sreward;
import com.qfedu.stussm.entity.Student;
import com.qfedu.stussm.service.intf.SrewardService;
import com.qfedu.stussm.vo.PageBeanVo;
import com.qfedu.stussm.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SrewardServiceImpl implements SrewardService {
    @Autowired
    private SrewardDao dao;
    //增加
    @Override
    public int add(Sreward sreward) {
        return dao.add(sreward);
    }
    //查询
    @Override
    public List<PageBeanVo> selectAll() {
        return dao.selectAll();
    }

    @Override
    public PageBeanVo queryPage(String stu_Aname, int page, int limit) {
        //1.开启分页
        PageHelper.startPage(page,limit);
        //2.PageInfo name="" name=null
        if(stu_Aname!=null && stu_Aname.length()>0){
            stu_Aname="%"+stu_Aname+"%";
        }else {
            stu_Aname=null;
        }
        PageInfo<Sreward> pageInfo=new PageInfo<>(dao.selectLikeAll(stu_Aname));
        //3.返回
        return new PageBeanVo(pageInfo.getTotal(),pageInfo.getList());
    }
    //修改
    @Override
    public R update(Sreward sreward) {
        if(dao.update(sreward)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }
    //删除
    @Override
    public R del(int id) {
        if(dao.del(id)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }
}
